package com.jmyu.meetappointment.util;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import cn.bmob.v3.BmobObject;
import cn.bmob.v3.listener.SaveListener;

import com.jmyu.meetappointment.bean.Meet;
import com.jmyu.meetappointment.ui.OnFinishedListenrn;


public class DataUtil  {
	private final static String TAG = "DataUtilTAG";
	private static Context context;
	public static String username = null;
	MyProgressDialog mProgressDialog;
	
	public DataUtil(Context context) {
		this.context = context;
	}


	/**
	 * 添加当前周的会议室数据
	 */
	public static void AddMeetsByWeek(final String[] weeks,final OnFinishedListenrn onFinishedListenrn) {
		final List<BmobObject> meets = new ArrayList<BmobObject>();
				for (int i = 0; i < weeks.length; i++) {
					for (int m = 1; m < 5; m++) {
						Meet meet = new Meet();
						meet.setMeet_name("AAA");
						meet.setDay(weeks[i]);
						meet.setState_id(1 + "");
						meet.setTime_id(m + "");
						meets.add(meet);
					}
				}
				new BmobObject().insertBatch(context, meets,
						new SaveListener() {

							@Override
							public void onSuccess() {
								Log.i(TAG, "添加A会议室成功");
								meets.clear();
								for (int i = 0; i < weeks.length; i++) {
									for (int m = 1; m < 5; m++) {
										Meet meet = new Meet();
										meet.setMeet_name("BBB");
										meet.setDay(weeks[i]);
										meet.setState_id(1 + "");
										meet.setTime_id(m + "");
										meets.add(meet);
									}
								}
								new BmobObject().insertBatch(context, meets,
										new SaveListener() {

											@Override
											public void onSuccess() {
												Log.i(TAG, "添加B会议室成功");
												meets.clear();
												for (int i = 0; i < weeks.length; i++) {
													for (int m = 1; m < 5; m++) {
														Meet meet = new Meet();
														meet.setMeet_name("CCC");
														meet.setDay(weeks[i]);
														meet.setState_id(1 + "");
														meet.setTime_id(m + "");
														meets.add(meet);
													}
												}
												new BmobObject().insertBatch(context, meets,
														new SaveListener() {

															@Override
															public void onSuccess() {
																Log.i(TAG, "添加C会议室成功");
																meets.clear();
																for (int i = 0; i < weeks.length; i++) {
																	for (int m = 1; m < 5; m++) {
																		Meet meet = new Meet();
																		meet.setMeet_name("DDD");
																		meet.setDay(weeks[i]);
																		meet.setState_id(1 + "");
																		meet.setTime_id(m + "");
																		meets.add(meet);
																	}
																}
																new BmobObject().insertBatch(context, meets,
																		new SaveListener() {

																			@Override
																			public void onSuccess() {
																				Log.i(TAG, "添加D会议室成功");
																				onFinishedListenrn.onAddMeetFinish();
																			}

																			@Override
																			public void onFailure(int arg0, String arg1) {
																				Log.i(TAG, "添加D会议室失败：" +arg0+"+"+ arg1);
																			}
																		});
															}

															@Override
															public void onFailure(int arg0, String arg1) {
																Log.i(TAG, "添加C会议室失败：" +arg0+"+"+ arg1);
															}
														});
												
											}

											@Override
											public void onFailure(int arg0, String arg1) {
												Log.i(TAG, "添加B会议室失败：" +arg0+"+"+ arg1);
											}
										});
								
								
							}

							@Override
							public void onFailure(int arg0, String arg1) {
								Log.i(TAG, "添加A会议室失败：" +arg0+"+"+ arg1);
							}
						});

	}
	
}
